﻿using System.Windows.Markup;
namespace CoreModule
{
    /// <summary>
    ///   Enum 绑定扩展
    /// </summary>
    public class EnumBindingSourceExtension : MarkupExtension
    {
  
        public Type EnumType
        {
            get;set;
        }
        public EnumBindingSourceExtension()
        {
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
        
            if (null == EnumType)
            {
                return new List<string>();
            }
            var actualEnumType = Nullable.GetUnderlyingType(EnumType) ?? EnumType;
            var enumValues = Enum.GetValues(actualEnumType);
            if (actualEnumType == EnumType)
            {
                return enumValues;
            }
            var tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
            enumValues.CopyTo(tempArray, 1);
            return tempArray;
        }
    }
}
  
